我正在构建一个应用程序,我需要在图表中处理一个位置.该位置具有X,Y的值以及北,东,南和纬的方向.我认为这个位置可能是Struct因为它代表该图中的单个值.
我研究并思考Structs并发现这些规则使用Struct:
这是我未完成的一个例子Struct:
public struct Position
{
public long PositionX { get; set; }
public long PositionY { get; set; }
public CompassPoint CompassPoint { get; set; }
}
public enum CompassPoint : byte
{
North,
East,
South,
West
}
Run Code Online (Sandbox Code Playgroud)
我想知道如何计算我的字节大小Struct以及如何知道它是否是不可变的?
谢谢.
更新:
好的.根据响应,似乎我Struct传递了16个字节,因为只有两个long有16个字节+ 1个字节CompassPoint.
但是一个额外的问题是:我获得的是使用Struct16字节和不可变的?看看DateTime Struct,它似乎有16个字节?任何问题?
IoC = 控制反转
DIP = 依赖倒置原理(SOLID 中的 D)
IoC == DIP?我想是这样的,确实如此。
构建软件的世界已经如此混乱,为什么还要用这么多词来表达同样的事情呢?
(我知道DI (依赖注入),它与DIP和IoC不同)
更新:
根据答案,我们可以说: ( DI ) + ( IoC ) = (依赖倒置原理) ?
我有一个需要授权才能访问所有控制器/操作的应用程序.登录和错误控制器/操作除外.
在这种情况下,以防御方式工作最好是保持对所有控制器/操作的默认限制访问(没有授权属性),并且只选择那些不使用自定义属性的自定义属性.
你们这样做过吗?
我有一个MVC过滤器,如果记录用户有权访问它们,则在所有操作之前执行:
public class ValidatePermissionAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext context)
{
bool isAuthorized = false;
//Logic that verify if logged user have permission to access the requested Controller/Action
...
//Redirect to a page Error if Logged User don't have Authorization
if (!isAuthorized)
{
RouteValueDictionary redirectTargetDictionary = new RouteValueDictionary();
redirectTargetDictionary.Add("action", "Erro");
redirectTargetDictionary.Add("controller", "Index");
context.Result = new RedirectToRouteResult(redirectTargetDictionary);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在想最好的方法.我可以创建一个空白自定义属性并放入控制器不需要授权并在我的过滤器中 …
我在Backbone.js中是非常新的,所以,backbone.js本质上是将类结构带到javascript?如果是这样,那不是一个向后的步骤吗?根据Douglas Crockford的说法,Javascripts原型更强大.
我正在为我的宠物软件构建API,我遇到以下情况:
使用其他服务的服务.我有一个服务使用另一个服务加载程序集,我应该在加载程序集的服务或使用该服务的服务上抛出异常?
AssemblyService:
public class AssemblyService : IAssemblyService
{
public Assembly Load(string assemblyName)
{
Assembly assembly;
try
{
assembly = Assembly.Load(assemblyName);
}
catch
{
assembly = null;
}
return assembly;
}
...
}
Run Code Online (Sandbox Code Playgroud)
使用AssemblyService的服务:
public class CommandService : ICommandService
{
private readonly IAssemblyService assemblyService;
public CommandService(IAssemblyService assemblyService)
{
this.assemblyService = assemblyService;
}
public CommandOutput Process(string inputCommand, string requestInfo)
{
string commandName = GetAssemblyName(inputCommand);
string args = GetArgs(inputCommand);
Assembly assembly = assemblyService.Load(commandName);
if (assembly == null) throw new UnknownCommandException(commandName);
ICommand command …Run Code Online (Sandbox Code Playgroud) 我试图理解单声道的android如何工作,我在官方网站上找不到这个解释.
考虑到android读取java字节码,Mono for Android是一个需要安装在Android设备上的框架,还是一个编译成java字节码的编译器?
我正在尝试从HandleErrorAttribute中从我的派生类中记录404 错误.
这是我的班级:
public class LogExceptionAttribute : HandleErrorAttribute
{
public override void OnException(ExceptionContext exceptionContext)
{
Log.LogException(exceptionContext.Exception, exceptionContext.Exception.Message);
base.OnException(exceptionContext);
}
}
Run Code Online (Sandbox Code Playgroud)
我在应用程序中得到所有异常,但我没有得到404错误.我想得到各种错误,例外.
我发现这个WebServer与Visual Studio一起使用(http://cassinidev.codeplex.com/)
任何人都知道这是否比VS WebServer更好?
我正在尝试解决EF中的问题以更新我的实体中的集合:
[TestMethod]
public void DeveEditarUsuarioNoRepositorio()
{
Usuario usuario = _usuarioRepository.GetById(1);
usuario.Nome = "Samla Peidorreira";
usuario.Email = "samlapeidanascalca@samlapeidanascalca.com";
usuario.DataNascimento = new DateTime(1988, 11, 19, 4, 23, 54, 0);
usuario.Sexo = (Sexo)Convert.ToByte(Sexo.Masculino);
usuario.Telefone = null;
usuario.Credencial.Status = (Status)Convert.ToByte(Status.Ativo);
//That's the collection I want to update
usuario.Credencial.Perfis = new List<Perfil>() { new Perfil() { Nome = "Fotografos", DataEdicao = new DateTime(1996, 2, 1, 12, 15, 42, 27), Deletado = true, Status = false, Tipo = 3 } };
usuario.Credencial.NomeUsuario = "samlapeidanascalca";
usuario.Credencial.Senha = …Run Code Online (Sandbox Code Playgroud) 我不明白为什么这个while循环是无限的:
window.prevRandomNumber = -1;
function getRandomNumber(limit) {
if (!limit)
limit = 9;
var actualRandomNumber = Math.floor((Math.random() * limit) + 1);
while (window.prevRandomNumber == actualRandomNumber) {
actualRandomNumber = Math.floor((Math.random() * limit) + 1)
}
window.prevRandomNumber = actualRandomNumber;
return actualRandomNumber;
}
Run Code Online (Sandbox Code Playgroud)
QUnit测试:
test("getRandomNumber() should never return the same number once and again", function () {
//http://www.askageek.com/2006/01/31/javascript-random-function-that-does-not-return-two-consecutive-identical-results/
var prevNumber, actualNumber, assertResult;
for (var i = 0; i <= 200; i++) {
actualNumber = getRandomNumber();
assertResult = prevNumber != actualNumber;
equal(assertResult, true); …Run Code Online (Sandbox Code Playgroud) 当我推送和拉取我的数据是加密?
我知道当我与github建立连接时使用的是SSH密钥和RSA算法.
.net ×5
asp.net ×3
c# ×3
asp.net-mvc ×2
javascript ×2
android ×1
backbone.js ×1
cassini ×1
cryptography ×1
exception ×1
git ×1
github ×1
log4net ×1
mono ×1
qunit ×1
repository ×1
struct ×1
terminology ×1
webserver ×1
while-loop ×1